<?php
namespace app\logic\yuql;


use app\api\model\yuql\Alipay;
use app\api\model\yuql\Order;
use app\api\model\yuql\Seckill;
use app\services\yuql\PayServices;

class FieryLogic
{

    /**
     * yuql
     * 热门商品查找
     * @param $params
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public static function HaveSeenGoodsOrder($params){
        if (!empty($params['title'])){
            $userSearchGoods = Seckill::userSearchGoods($params['title']);
            if (!$userSearchGoods) $searchGoodsId = [];
            foreach ($userSearchGoods as $v){
                $goods_id = $v['goods_id'];
                //将所有该用户的订单商品id存入数组
                $searchGoodsId[] = $goods_id;
            }
        }else{
            $searchGoodsId = [];
        }

        $goodsOrders = Order::goodsOrders(['uid'=>$params['user_id']]);
        if (!$goodsOrders) throw new \Exception('没有订单商品');
        foreach ($goodsOrders as $v){
            $goods_id = $v['goods_id'];
            //将所有该用户的订单商品id存入数组
            $recommendGoodsId[] = $goods_id;
        }
        //将用户搜索的商品id和购买的商品id进行拼接
        $recommendGoodsIdSum = array_merge($searchGoodsId,$recommendGoodsId);
        foreach ($recommendGoodsIdSum as $v){
            $goodsList = Seckill::RecommendGoodsList(['goods_id' => $v]);
            $recommendGoodsAll[] = $goodsList;
        }
        return $recommendGoodsAll;
    }

}